cc.Class({
    extends: cc.Component,

    properties: {
        spBj: cc.Sprite,
        btnLevel: cc.Button,
        txtLevel: cc.Label,
        pfLevel: null,
        levelData: null,
        maxPassLevel:null,
    },

    //设置关卡等级
    setLevel: function (number, data) {
        this.maxPassLevel =window.gameConfig.getGameConfigData("level");
        if(this.maxPassLevel == null)this.maxPassLevel = 1;
        this.txtLevel.string = number + 1;
        this.levelData = data;
        let url = "";
        let color= null;
        if (this.maxPassLevel >= number + 1) 
        {
            url = "check";
            color = new cc.color(255,255,255,255);
        }
        else 
        {
            url = "uncheck";
            color = new cc.color(99,89,89,255);
        }

        this.txtLevel.node.color = color;

        // let spUrl = "gameLevel/" + url;
        // window.onLoadSpriteRes(spUrl,cc.SpriteFrame,this.onLoadRes);
        this.onLoadRes(url)
    },

    onLoadRes: function (url) {
        var self = this;
        // if(spSprite == null)return;
        // this.spBj.spriteFrame = spSprite;
        cc.loader.loadRes("image/gameLevel/" + url, cc.SpriteFrame, function (err, spriteFrame) {
            self.spBj.spriteFrame = spriteFrame;
        });
    },

    //点击关卡 进入游戏
    onBtnLevelCheckEvent: function () {
        window.audioMgr.prototype.playButtonAudio();
        if (this.levelData.levelNumber <= this.maxPassLevel) 
        {
            window.setLevelData(this.levelData);
            let maxLevel = window.gameConfig.getGameConfigData("level");
            if(maxLevel < this.txtLevel.string)
            {
                window.gameConfig.saveLevel(this.txtLevel.string);
            }
            cc.director.loadScene("gameMain");
            removeNodeByParent(this.pfLevel.node);
        } 
        else 
        {
            cc.log("关卡未解锁");
        }
    },
});